﻿using System.Reflection;
using UnityEngine.Events;
using UnityEngine.UI;

namespace WzhModule.GM
{

    public class WzhGMToggle : Toggle
    {

        public MemberInfo MemberInfo;

        private int Id = -1;
        private UnityAction<int, bool> Action = null;

        public void AddAction(UnityAction<int, bool> action, int id)
        {
            Id = id;
            Action = action;
            onValueChanged.AddListener(ValueChanged);
        }

        private void ValueChanged(bool value)
        {
            Action.Invoke(Id, value);
        }

        public void Clear()
        {
            Id = -1;
            Action = null;
            onValueChanged.RemoveAllListeners();
        }

    }

}
